import os
import sys

sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
import boto3
from config import FORMAL_S3_CONFIG


class Operation_aws_glue():
    def __init__(self):
        self.glue = boto3.client('glue', region_name=FORMAL_S3_CONFIG['region_name'],
                                 aws_access_key_id=FORMAL_S3_CONFIG['access_key'],
                                 aws_secret_access_key=FORMAL_S3_CONFIG['secret_key'])

    def get_partitions(self, db, table_name):
        paginator = self.glue.get_paginator('get_partitions')
        page_iterator = paginator.paginate(
            DatabaseName=db,
            TableName=table_name,
            ExcludeColumnSchema=True)
        exists_partitions = []
        for response in page_iterator:
            for one in response['Partitions']:
                exists_partitions.append(one['Values'])
        return exists_partitions

